# _*_ coding : utf-8 _*_
# @Time : 2024-04-07 17:39
# @Author : haowen
# @File : DataParserInTime_Test
# @Project : p2024-hyperthyroidism-screening
import os
from datetime import datetime
import re
import shutil
from ExcelParser import load_book
from VarDefine import *

# 获取文件的修改时间
def get_file_modified_time(file_path):
    mod_time = os.path.getmtime(file_path)
    return datetime.fromtimestamp(mod_time)

def get_all_images(folder_path):
    image_files = []
    files_last_name = []
    for root, dirs, files in os.walk(folder_path):
        for file in files:
            if file.lower().endswith((".png", ".jpg", ".jpeg", ".gif")):
                image_files.append(os.path.join(root, file))
                files_last_name.append(os.path.basename(file))

    return image_files,files_last_name

# 读取xlsx
data_book = load_book("糖网筛查_20240403 090453.xlsx")

# 指定文件夹路径
folder_path = "二院累计数据20240402/20211201"
# folder_path = "二院累计数据20240402"
# 调用函数获取所有图片文件列表
image_files, files_last_name = get_all_images(folder_path)

# 打印所有筛选出的图片文件路径和修改时间
for img_file, file_last_name in zip(image_files, files_last_name):
    mod_time = get_file_modified_time(img_file)
    # print(f"文件名: {file_last_name}")
    # print(f"修改时间: {mod_time}")

    # 格式化输出为指定格式的字符串
    converted_datetime_str1 = mod_time.strftime("%Y%m%d%H")
    # print("转换后的日期时间字符串:", converted_datetime_str1)
    for key, value in data_book.items():
        mytime_str = value["check_data"]
        # 将字符串转换为 datetime 对象
        mytime = datetime.strptime(mytime_str, "%Y-%m-%d %H:%M:%S")
        # 格式化输出为指定格式的字符串
        converted_datetime_str2 = mytime.strftime("%Y%m%d%H%M")
        # print("data的:", converted_datetime_str2)
        if converted_datetime_str1 == converted_datetime_str2:
            # print(value["name"])
            second_character = file_last_name[1]
            # print("文件名的第二个字符:", last_character)
            if second_character == "L" or second_character == "R":
                print("yes")
                # print(value["right"])
        else:continue

